package bishizhuanyong.度小满;

import java.util.Scanner;

public class main2 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int num = sc.nextInt();
        for (int i=0;i<num;i++){
            int len = sc.nextInt();
            int p = sc.nextInt();
            String s = sc.next();
            System.out.println(cal(s,len,p));
        }
    }
    public static int cal(String s,int len,int p){
        if (len==1)
            return 0;
        if (len==2)
            return s.charAt(0)==s.charAt(1)?0:1;
        int[] hash=new int[26];
        for (int i=0;i<s.length();i++){
            hash[s.charAt(i)-'a']++;
        }
        int max=-1;
        for (int i=0;i<26;i++)
            max=Math.max(hash[i],max);
        return len-max;
    }
}
